package com.bqtt.tumor.demo.presentation.controller;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.bqtt.tumor.demo.business.BrainTumourService;
import com.bqtt.tumor.demo.business.DiagnosisMethodService;
import com.bqtt.tumor.demo.common.MyBeanFactory;
import com.bqtt.tumor.demo.entity.Feature;
import com.bqtt.tumor.demo.entity.SystemUser;
import com.bqtt.tumor.demo.presentation.model.tumor_treat.SheetItem;

@Controller
@RequestMapping("/doctor")
@SessionAttributes(value={"currentUser","historySearchCondition"})
public class doctor {

	
	
	@RequestMapping("/diagnoseBrainTumour")
	public String diagnoseBrainTumor(@ModelAttribute("currentUser") SystemUser user,  ModelMap model)
	{
		if(user.getSessionState()==0)
		{
			return ((login)MyBeanFactory.getBean("login")).showHomePage(model, user);
		}
		
		List<Feature> featureList = BrainTumourService.getAllClinicInfoList();
		model.put("featureList", featureList);
		model.put("feature_count", featureList.size());
		List<SheetItem> sheet = new ArrayList<SheetItem>();
		sheet.add(new SheetItem("血糖含量","mg/ml"));
		sheet.add(new SheetItem("血压","mmHg"));
		sheet.add(new SheetItem("血小板浓度","ug/ml"));
		model.put("sheet", sheet);
		
		return "diagnosis/brain_tumour";
	}
	
	@RequestMapping("/diagnoseBrainTumourResult")
	public String diagnoseBrainTumorResult(@ModelAttribute("currentUser") SystemUser user, HttpServletRequest request, @RequestParam(value="features",required=false) String [] features, ModelMap model)
	{
		if(user.getSessionState()==0)
		{
			return ((login)MyBeanFactory.getBean("login")).showHomePage(model, user);
		}
		
		
		
		String arr[] = request.getParameterValues("features");
//		String feature_count_string = request.getParameter("feature_count");
//		
//		Integer feature_count =0;
//		
//		if(feature_count_string!=null)
//			feature_count = Integer.parseInt(feature_count_string);
//		
//		int selectedCount = 0;
//		if(arr==null)
//			selectedCount =0;
//		else
//			selectedCount = arr.length;
//
//
//		int allCount = feature_count==null ? 0 : feature_count;
//		
//		double ratio = 0.0;
//		if(allCount>0)
//			ratio  =  (double)selectedCount*100.0/(double)allCount ;
//		
//		
//		model.put("ratio", ratio);
		List<String> selectedFeatures = new ArrayList<String>();
		for(String item:arr)
		{
			selectedFeatures.add(item);
		}
		String result  =  DiagnosisMethodService.diagnoseByClassical(selectedFeatures);
		
		
		model.put("ratios", result);
		
		
		return "diagnosis/brain_tumour_result";
	}
	
	
	@RequestMapping("/diagnoseLiverTumour")
	public String diagnoseLiverTumour(@ModelAttribute("currentUser") SystemUser user,  ModelMap model)
	{
		if(user.getSessionState()==0)
		{
			return "login";
		}
		return "diagnosis/liver_tumour";
	}
	
}
